package com.mlf.observer.demo01;

import lombok.Data;

import java.util.Observable;
import java.util.Observer;

/**
 *   观察者一号-温度显示器
 */
@Data
public class TemperatureDisplay implements Observer {
    private String displayName;
    public TemperatureDisplay(String displayName) {
        this.displayName = displayName;
    }

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof TemperatureSensor) {
            double temperature = (Double) arg;
            System.out.println(displayName + ": 当前温度为:" + temperature + "°C");

        }
    }
}
